﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Bing;

namespace demo
{
    public class Demo_Translate_20110912
    {
        public static string Translate(string sourceText)
        {
            string AppId = "B692A148D1624C4E3C1248C8E5DDC209E524D2C4";

            SearchRequest searchRequest = new SearchRequest() { AppId = AppId, Query = sourceText, Market = "en-US" };

            TranslationRequest translationRequest = new TranslationRequest();  // 宣告 TranslationRequest 並實例化
            translationRequest.SourceLanguage = "En";  // 來源語系
            translationRequest.TargetLanguage = "zh-CHS";  // 目的語系

            TranslationResponse response = API.Translation(searchRequest, translationRequest);

            if (response.TranslationResults.Count > 0)  // 翻譯回傳值大於0時
                return response.TranslationResults[0].TranslatedTerm;
            else
                return "";
        }
    }
}
